package junit.test;


import java.util.Date;
import java.util.List;

import net.hust.bean.User;
import net.hust.service.UserService;

import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Usertest {

	private static UserService userService;
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		try {
			ApplicationContext act = new ClassPathXmlApplicationContext("beans.xml");
			userService = (UserService)act.getBean("userServiceBean");
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Test
	public void save(){
		userService.save(new User("abcdef", "abcdef","ccca@ac", new Date()));
	}
	@Test
	public void update(){
		User User = userService.find(1);
		//User.setGender(Gender.WOMEN);
		User.setPasswd("abcd");
		User.setUserName("li");
		userService.update(User);
	}
	
	@Test
	public void delete(){
		userService.delete(1);
	}
	
	@Test
	public void findbyname(){
		
	    String pw =	userService.findPwByNm("zsan");
		System.out.print(pw);
	}
	
	@Test
	public void list(){
		List<User> us = userService.list();
		for(User u: us)
			System.out.println(u.getPasswd());
	}
	
	

}
